
//
// This is example code from Chapter 9.7.1 "Argument types" of 
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
//
#ifndef DATE_H //added MF A2
#define DATE_H //added MF A2

#include <iostream>

using namespace std;

//------------------------------------------------------------------------------
/*
class Year {        // year in [min:max) range
    static const int min = 1800;
    static const int max = 2200;
public:
    class Invalid 
	{ 
		
	};
    
	Year(int year) : thisYear(year) 
	{ 
		if (year<min || max<year) 
			throw Invalid(); 
	}
	
    int get_year() 
	{ 
		return thisYear; 
	}
private:
    int y;
};
*/
//------------------------------------------------------------------------------

class Date {//added MF A2
public://added MF A2
    enum Month {//added MF A2
        JAN=1, FEB, MAR, APR, MAY, JUN, JULY, AUG, SEP, OCT, NOV, DEC
    };

    Date(int year, Month month, int day) //: thisYear(year), thisMonth(month), thisDay(day) // check for valid date and initialize
	//constrcutor
    {
		y=year;//added MF A2
		m=month;//added MF A2
		d=day;//added MF A2
        if (day<1 || 31<day)
			cerr<< "Bad day";
			//throw Invalid();
			
		if(month<1 || month>12)
			cerr<< "bad month";
			//throw Invalid();
    }
	
	int year() const//added MF A2
	{
		return y;
	}
	Month month() const//added MF A2
	{
		return m;
	}
	int day() const//added MF A2
	{
		return d;
	}

    // ...
private:
    int y;
    Month m;
    int d;   // day
};

#endif
/*void add_day()
{
	++thisDay();
}*/

//------------------------------------------------------------------------------
/*
int main()
try
{
    //Date dx1(Year(1998), 4, 3);         // error: 2nd argument not a Month
    //Date dx2(Year(1998), 4, Date::mar); // error: 2nd argument not a Month
    //Date dx2(4, Date::mar, Year(1998)); // error: 1st argument not a Year
    //Date dx2(Date::mar, 4, Year(1998)); // error: 2nd argument not a Month
    Date today(Year(1978), Date::JUN, 25);  // ok
	Date tomorrow(today.add_day());
    //This weird and unlikely error would still not be caught until run-time:
    Date dx5(Year(4), Date::MAR, 1998);   //  run-time error: Year::Invalid
}
catch (Year::Invalid&) {
    cerr << "error: Invalid year\n"; 
    return 1;
}
catch (...) {
    cerr << "Oops: unknown exception!\n"; 
    return 2;
}

//------------------------------------------------------------------------------
*/